package com.example.home.logistics.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.logistics.bean.LogisticsDetailBean;
import com.example.home.tool.OKHttpTool;

import static com.example.home.tool.StaticActi.ip;

public class LogisticsCardDetail extends AppCompatActivity {
    private ImageView back;
    private ImageView newsImageView;
    private TextView brief;
    private TextView freight;
    private TextView freightIntroductionTextView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logistics_card_detail);
        Intent intent = getIntent();
        String logisticsId = intent.getStringExtra("LogisticsId");
        initView();
        getData(logisticsId);
    }

    private void getData(String logisticsId) {
        OKHttpTool.doNetRequest("prod-api/api/logistics-inquiry/logistics_company/" + logisticsId,
                OKHttpTool.GET,
                LogisticsDetailBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        LogisticsDetailBean logisticsDetailBean = (LogisticsDetailBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Glide.with(LogisticsCardDetail.this).load(ip+logisticsDetailBean.getData().getImgUrl()).into(newsImageView);
                                brief.setText("公司简介："+logisticsDetailBean.getData().getIntroduce());
                                freight.setText("运输方式介绍："+logisticsDetailBean.getData().getShippingMethod());
                                freightIntroductionTextView.setText("运费介绍："+logisticsDetailBean.getData().getPriceList());
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                }
        );
    }

    private void initView() {
        back = findViewById(R.id.back);
        newsImageView = findViewById(R.id.newsImageView);
        brief = findViewById(R.id.brief);
        freight = findViewById(R.id.freight);
        freightIntroductionTextView = findViewById(R.id.freightIntroductionTextView);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogisticsCardDetail.this.finish();
            }
        });
    }
}